<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 400px;
            height: 400px;
            display: flex;
            flex-direction: column;
            align-items: center;
            border: 1px solid darkgray;
            margin: 100px auto;
        }
        button{
            width: 200px;
            height: 50px;
        }
        img{
            width: 300px;
            height: 300px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div>
        <button id="btn" onclick="fn()">隐藏图片</button>
        <img src="./images/1.gif" alt="">
    </div>
    <script>
        var btn = document.getElementById('btn');
        var img = document.getElementsByTagName('img')[0];
        function fn(){
            if(btn.innerHTML === '隐藏图片'){
                img.style.display = 'none';
                btn.innerHTML = '显示图片'

            }else{
                btn.innerHTML = '隐藏图片';
                img.style.display = 'block'
            }
        }
    </script>
</body>
</html>